﻿namespace com.savealot.Extensions.GuidExtensions
{
    using System;

    public static class GuidExtensions
    {
        #region Methods

        /// <summary>
        /// Convert this specified instance of a Guid to a short Guid (a 22-byte string). To convert the short Guid back to a Guid, see StringExtension.FromShortGuid.
        /// </summary>
        /// <param name="guid"></param>
        /// <returns></returns>
        public static string ToShortGuid( this Guid guid )
        {
            string s = Convert.ToBase64String( guid.ToByteArray( ) );
            s = s.Replace( "/", "_" ).Replace( "+", "-" );
            return s.Substring( 0, 22 );
        }

        #endregion Methods
    }
}